<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="app">
    <h1>persons:{{persons}}</h1>
    <button @click="changePersons">changePersons</button>
</div>
<script src="../../JavaScript/vue.js"></script>
<script>
    /*
     数组更新检测：
       Vue将被侦听的数组的变更方法进行了包裹，所以它们将会触发视图更新这些变更方法包括：
          push()、pop()、shift()、unshift()、splice()、sort()、reverse()
    */
    const app = Vue.createApp({
        data() {
            return {
                persons: [
                    {id: 1, name: "陶品奇", age: 22}
                ]
            }
        },
        methods: {
            changePersons() {
                /* 1.直接接将原数组修改为新的数组(替换数组)
                  this.persons= this.persons.map((item) => {
                    return {id:1,name:"陶渊明",age:200}
                  })
                */
                //2.数组更新检测
                this.persons.push({id: 2, name: "陶渊明", age: 200})
            }
        }
    })
    app.mount("#app")
</script>
</body>
</html>